package com.kfm.jdbc.day0404.thread;

public class Ticket1 implements Runnable{

    // 定义100张票
    private int ticket = 100;

    @Override
    public void run() {
        // 模拟窗口一直在卖票
        while (true) {
            sellTicket();
        }
    }

    public synchronized void sellTicket(){

        if (ticket > 0) {
            // 模拟卖票时间
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 模拟卖票操作
            System.out.println(Thread.currentThread().getName() + " 正在卖第 " + ticket-- + "张票");
        }

    }
}
